package com.hunttown.mes.convert;

import com.google.common.collect.Lists;
import com.hunttown.mes.common.utils.BeanUtils;
import com.hunttown.mes.domain.AnalysisManageRightRoleAdminRel;
import com.hunttown.mes.rpc.domain.AnalysisManageRightRoleAdminRelDTO;
import com.hunttown.mes.rpc.exception.ConvertException;
import com.hunttown.mes.rpc.domain.enums.ErrorCode;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Collections;
import java.util.List;

/**
 * created by wangjunfu on 2018-11-26 15:05:54
 */
public class AnalysisManageRightRoleAdminRelConverts {

    private static Logger LOG = LoggerFactory.getLogger(AnalysisManageRightRoleAdminRelConverts.class);

    public static List<AnalysisManageRightRoleAdminRelDTO> convert(List<AnalysisManageRightRoleAdminRel> analysisManageRightRoleAdminRelList) {
        if (CollectionUtils.isEmpty(analysisManageRightRoleAdminRelList)) {
            return Collections.EMPTY_LIST;
        }

        List<AnalysisManageRightRoleAdminRelDTO> analysisManageRightRoleAdminRelListResult = Lists.newArrayList();
        for (AnalysisManageRightRoleAdminRel analysisManageRightRoleAdminRel : analysisManageRightRoleAdminRelList) {
            analysisManageRightRoleAdminRelListResult.add(convert(analysisManageRightRoleAdminRel));
        }
        return analysisManageRightRoleAdminRelListResult;
    }

    public static AnalysisManageRightRoleAdminRelDTO convert(AnalysisManageRightRoleAdminRel analysisManageRightRoleAdminRel) {
        try {
            return BeanUtils.copy(analysisManageRightRoleAdminRel, AnalysisManageRightRoleAdminRelDTO.class);
        } catch (Exception e) {
            LOG.error("AnalysisManageRightRoleAdminRel到AnalysisManageRightRoleAdminRelDTO转换失败!", e);
            throw new ConvertException(ErrorCode.CONVERT_ERROR, "AnalysisManageRightRoleAdminRel到AnalysisManageRightRoleAdminRelDTO转换失败", e);
        }
    }

    public static AnalysisManageRightRoleAdminRel convert(AnalysisManageRightRoleAdminRelDTO analysisManageRightRoleAdminRelDTO) {
        try {
            return BeanUtils.copy(analysisManageRightRoleAdminRelDTO, AnalysisManageRightRoleAdminRel.class);
        } catch (Exception e) {
            LOG.error("AnalysisManageRightRoleAdminRelDTO到AnalysisManageRightRoleAdminRel转换失败!", e);
            throw new ConvertException(ErrorCode.CONVERT_ERROR, "AnalysisManageRightRoleAdminRelDTO到AnalysisManageRightRoleAdminRel转换失败", e);
        }
    }

    public static List<AnalysisManageRightRoleAdminRel> converto(List<AnalysisManageRightRoleAdminRelDTO> manageRightRoleAdminRelDTOList) {
        if (CollectionUtils.isEmpty(manageRightRoleAdminRelDTOList)) {
            return Collections.EMPTY_LIST;
        }

        List<AnalysisManageRightRoleAdminRel> rightRoleUserRelListResult = Lists.newArrayList();
        for (AnalysisManageRightRoleAdminRelDTO manageRightRoleUserRel : manageRightRoleAdminRelDTOList) {
            rightRoleUserRelListResult.add(convert(manageRightRoleUserRel));
        }
        return rightRoleUserRelListResult;
    }
}